package com.cp.admin.modular.user.controller;

import com.cp.admin.modular.user.model.UserFriendGroup;
import com.cp.core.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.cp.admin.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.cp.admin.modular.user.service.IUserFriendGroupService;

/**
 * 控制器
 *
 * @author fengshuonan
 * @Date 2020-08-26 16:02:38
 */
@Controller
@RequestMapping("/userFriendGroup")
public class UserFriendGroupController extends BaseController {

    private String PREFIX = "/user/userFriendGroup/";

    @Autowired
    private IUserFriendGroupService userFriendGroupService;

    /**
     * 跳转到首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "userFriendGroup.html";
    }

    /**
     * 跳转到添加
     */
    @RequestMapping("/userFriendGroup_add")
    public String userFriendGroupAdd() {
        return PREFIX + "userFriendGroup_add.html";
    }

    /**
     * 跳转到修改
     */
    @RequestMapping("/userFriendGroup_update/{userFriendGroupId}")
    public String userFriendGroupUpdate(@PathVariable Long userFriendGroupId, Model model) {
        UserFriendGroup userFriendGroup = userFriendGroupService.selectById(userFriendGroupId);
        model.addAttribute("item",userFriendGroup);
        LogObjectHolder.me().set(userFriendGroup);
        return PREFIX + "userFriendGroup_edit.html";
    }

    /**
     * 获取列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return userFriendGroupService.selectList(null);
    }

    /**
     * 新增
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(UserFriendGroup userFriendGroup) {
        userFriendGroupService.insert(userFriendGroup);
        return SUCCESS_TIP;
    }

    /**
     * 删除
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Long userFriendGroupId) {
        userFriendGroupService.deleteById(userFriendGroupId);
        return SUCCESS_TIP;
    }

    /**
     * 修改
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(UserFriendGroup userFriendGroup) {
        userFriendGroupService.updateById(userFriendGroup);
        return SUCCESS_TIP;
    }

    /**
     * 详情
     */
    @RequestMapping(value = "/detail/{userFriendGroupId}")
    @ResponseBody
    public Object detail(@PathVariable("userFriendGroupId") Long userFriendGroupId) {
        return userFriendGroupService.selectById(userFriendGroupId);
    }
}
